namespace TXLooker.WorkItemExtention.WIQL
{
    using System;
    using System.Collections;
    using System.Globalization;

    internal static class Tools
    {
        public static void EnsureSyntax(bool condition, SyntaxError message, Node node)
        {
            if (!condition)
            {
                throw new SyntaxException(node, message);
            }
        }

        public static string FormatName(string s)
        {
            bool flag = (s.Length == 0) || !char.IsLetter(s, 0);
            int length = s.Length;
            for (int i = 0; (i < length) && !flag; i++)
            {
                if (!char.IsLetterOrDigit(s, i))
                {
                    flag = true;
                }
            }
            if (flag)
            {
                s = "[" + s + "]";
            }
            return s;
        }

        public static string FormatString(string s)
        {
            return string.Format(CultureInfo.InvariantCulture, "'{0}'", new object[] { string.Join("''", s.Split(new char[] { '\'' })) });
        }

        public static bool IsDateString(string s, CultureInfo culture)
        {
            DateTime result;
            return DateTime.TryParse(s, culture, DateTimeStyles.None, out result);
        }

        public static bool IsNumericString(string s)
        {
            ArrayList list = Parser.ParseLexems(s);
            if (list.Count == 1)
            {
                return (((NodeItem) list[0]).NodeType == NodeType.Number);
            }
            return false;
        }
    }
}

